"""
 The Argot marshalling routines for a book.  The TypeReader is
 handled by the TypeReaderAuto marshalling routine.
"""

import argot
from bookstore.Book import Book

class BookArgot(object):
    TYPENAME = argot.TypeName('book')

    def __init__(self):
        self.element = argot.TypeElement( self.bind )

    @staticmethod
    def construct(typelist, typemap):
        #print 'Constructing book'
        values = []
        item = typelist.head
        while item:
            values.append( item.get_object() )
            item = item.next

        isbn, title, description, author = values
        
        b = Book(isbn, title, description, author)
        #print b.__dict__
        #print 'done'
        return b

    @staticmethod
    def write(out, book, element):
        #print 'Writing book'
        tn = argot.U8Ascii.name
        out.write_named_object(tn, book.ISBN )
        out.write_named_object(tn, book.title )
        out.write_named_object(tn, book.description )
        out.write_named_object(tn, book.author )
